<template>
    
    <!-- 组件的模板 -->
    <div class="page" style="padding-bottom: 170px;">
        <div class="content">
            <div class="info_title">
                <div>项目需要签订电子协议</div>
                <div>请完善信息：</div>
            </div>
            <form>
                <div class="weui-cells_form">
                    <div class="weui-cell">
                        <div class="weui-cell__hd"><label class="weui-label">姓名</label></div>
                        <div class="weui-cell__bd">
                            <input class="weui-input" type="text" placeholder="请输入" :value="user_name" v-model="user_name" :disabled="is_authenticated" :class="{'isdisabled':(is_authenticated && andriodStyle)}">
                        </div>
                    </div>
                    <div class="weui-cell">
                        <div class="weui-cell__hd"><label class="weui-label">手机号</label></div>
                        <div class="weui-cell__bd">

                            <input class="weui-input" type="tel" placeholder="请输入" :value="phone" v-model="phone" :disabled="hasPhone" :class="{'isdisabled':(hasPhone && andriodStyle)}"> 
                        </div>
                    </div>
                    <div class="weui-cell">
                        <div class="weui-cell__hd"><label class="weui-label">身份证号</label></div>
                        <div class="weui-cell__bd">

                            <input class="weui-input" type="tel" placeholder="请输入" :value="user_identity" v-model="user_identity" :disabled="is_authenticated" :class="{'isdisabled':(is_authenticated && andriodStyle)}"> 
                        </div>
                    </div>
                    <div class="weui-cell">
                        <div class="weui-cell__hd"><label class="weui-label">居住地区</label></div>
                        <div class="weui-cell__bd">

                            <input class="weui-input" type="text" placeholder="请输入" :value="user_place" v-model="user_place"> 
                        </div>
                    </div>
                    <div class="weui-cell">
                    </div>
                </div>
            </form>
        </div>
        <div class="btn-box bg-colorbtn fixed" :style="{bottom:iPhoneX ? '34px' : '0'}">
            <a href="javascript:;" class="weui-btn weui-btn_primary" v-if="user_name&&phone&&user_identity&&user_place"  @click='sureSign'>下一步</a>
            <a href="javascript:;" class="weui-btn weui-btn_primary weui-btn_disabled" v-else>下一步</a>
        </div>            
    </div>
    
</template>

<script>
    /**
     *  引入工具类库 或 Native API
     *  example : import widget from 'gapi/widget'
     */
    import commonPage from 'clientApi/commonPage.js'
    import cache from 'gapi/cache.js'
    import * as util from 'js/util.js'
    import widget from 'gapi/widget'
    import clientUi from 'gapi/clientUi.js'
    import clientUtil from 'clientApi/util'
    import userCenterApi from 'clientApi/userCenterApi'
    /**
     *  引入组件 以及 组件接口(Action)
     *  example : import Somecomponents from 'components/Somecomponents/Somecomponents'
     */

    /**
     *  组件实例对象
     */
    export default {
        components: {

        },
        data: function(){
            return{
                iPhoneX: false,
                user_name: '',
                phone: '',
                user_identity: '',
                user_place: '',
                andriodStyle: true,
                is_authenticated: false,
                hasPhone: false,
                hasAddress: false,
                user_id: '',
                protocol_order_id: '',//合同編號
            }
        },
        vuex: {
            getters: {

            },
            actions: {

            }
        },
        methods: {
            /**
             * 初始化
             * @method init
             * @public
             * @return {Null} void
             */
            init (){
                //ios和安卓样式不兼容
                if(util.OS() =='ios'){
                    this.andriodStyle = false
                }else{
                    this.andriodStyle = true
                }
                this.iPhoneX = /iphone/gi.test(navigator.userAgent) && (screen.height == 812 && screen.width == 375);
                this.checkRealname();
                this.user_id = util.getUrddataString('user_id')
                this.protocol_order_id = util.getUrddataString('protocol_order_id')
            },
            //检测是否进行了实名认证
            checkRealname (){
                commonPage.loadPageStatus('loading')                          
                util.ajax({
                    url:'/user/check_real_name_authentication',
                    type:'GET',
                    data:{},
                    timeout:10000,
                    success:(data) => {
                        commonPage.loadPageStatus('loadSuccess')
                        if(data.errno == 0){
                            this.user_name = data.data.real_name
                            this.user_identity = data.data.idnumber
                            if(data.data.authenticated == 1){
                                this.is_authenticated = true                               
                            }else{
                                this.is_authenticated = false
                            }
                            if(data.data.mobile){
                                this.phone = data.data.mobile
                                this.hasPhone = true
                            }else{
                                this.phone = '';
                            }
                            if(data.data.detail_address){
                                this.user_place = data.data.detail_address
                                this.hasAddress = true
                            }else{
                                this.user_place = '';
                            }
                        }else{
                            widget.toast(data.errmsg)
                        }
                    },
                    error:function(status){
                        commonPage.loadPageStatus('loadSuccess')
                        widget.toast('服务器异常')
                    }
                })
            },
            //存储信息
            sureSign (){
                commonPage.loadPageStatus('loading')                          
                util.ajax({
                    url:'/user/real_name_authentication',
                    type:'GET',
                    data:{
                        name: this.user_name,
                        idnumber: this.user_identity,
                        detail_address: this.user_place,
                        mobile: this.phone,
                    },
                    timeout:10000,
                    success:(data) => {
                        commonPage.loadPageStatus('loadSuccess')
                        if(data.errno == 0){
                            let url = `user_id=${this.user_id}&protocol_order_id=${this.protocol_order_id}`
                            location.href = "dmsaas://SignContract?urdData="+encodeURIComponent(url)
                        }else{
                            widget.toast(data.errmsg)
                        }
                    },
                    error:function(status){
                        commonPage.loadPageStatus('loadSuccess')
                        widget.toast('服务器异常')
                    }
                })
            }
        },
        created(){

            this.init();
            
        }
        
    }

    
</script>

<!-- CSS 样式 -->
<!-- <style src="static/css/global.css"></style> -->
<style src="../../node_modules/weui/dist/style/weui.css"></style>
<style src="../../static/css/common.css"></style>
<style>
    .page{
        background: #FFFFFF;
    }
    .weui-cells_form{
        text-align: center;
    }
    .weui-cell{
        height: 28px;
    }
    .info_title{
        font-family: PingFangSC-Semibold;
        font-size: 24px;
        color: #333333;
        letter-spacing: 1px;
        font-weight: bolder;
        padding: 32px 24px;
    }
    .weui-cell__hd{
        text-align: left;
        font-size: 14px;
        color: #666666;
        letter-spacing: 0;
    }
    .weui-input{
        font-size: 16px;
        letter-spacing: 0;
    }
    .weui-cell {
        padding: 12px 12px 12px 30px;
    }
    .weui-cell:before{
        content:" ";
        position:absolute;
        left:0;
        top:0;
        right:0;
        height:1px;
        border-top:1px solid #e5e5e5;
        color:#e5e5e5;
        -webkit-transform-origin:0 0;
        transform-origin:0 0;
        -webkit-transform:scaleY(0.5);
        transform:scaleY(0.5);
        left:24px;
        right:24px;
        z-index:2;
    }
</style>



